const express = require('express');
const body = require('body-parser');   //接受普通post 数据
const multer= require('multer');    //接受POST 文件数据


let server = express();

server.listen(8080);

server.use(body.urlencoded({extended: false}));

let multerObj = multer({dest: './upload/'});
server.use(multerObj.any());

server.post('/api',(req,res)=>{

  if(req.headers['origin']=='null' || req.headers['origin'].startsWith('http://localhost'))
  {
      res.setHeader('Access-Control-Allow-Origin','*');  //设置域
  }
  res.send('test');

  console.log(req.body);
  console.log(req.files);
});

server.use(express.static('./www/'));
